//
//  HFOLOuTuiViewController.m
//  HFOuLiao
//
//  Created by haifeng on 16/7/6.
//  Copyright © 2016年 sangziwangluo. All rights reserved.
//

#import "HFOLOuTuiViewController.h"
#import "HFOLsectionBar.h"

@interface HFOLOuTuiViewController () <UIScrollViewDelegate,OLsectionBarDelegate>

@property (nonatomic, strong) HFOLsectionBar *sectionBar;
@property (nonatomic, strong) NSMutableArray *titleArray;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *tableViewArray;

@end

@implementation HFOLOuTuiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpSectionBar];
    [self setUpScrollView];
    [self setUpTableView];
    UITabBarItem *barBtn = [[UITabBarItem alloc] initWithTitle:@"偶推" image:[[UIImage imageNamed:@"tabbar_home_no_press"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]  selectedImage:[[UIImage imageNamed:@"tabbar_home_pressed"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    self.tabBarItem = barBtn;
    _sectionBar.sectionBardelegate = self;
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 子控制器的配置
- (void)setUpSectionBar{
    _sectionBar = [[HFOLsectionBar alloc] init];
    _sectionBar.frame = CGRectMake(0, 49, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 15);
    _sectionBar.contentSize = _sectionBar.bounds.size;
    _titleArray = [NSMutableArray arrayWithObjects:@"默认排序",@"粉丝数量",@"按评分数",@"按通话量", nil];
    _sectionBar.titleArray = _titleArray;
    _sectionBar.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 15);
    [self.view addSubview:_sectionBar];
}

- (void)setUpScrollView{
    _scrollView = [[UIScrollView alloc] init];
    _scrollView.frame = CGRectMake(0, _sectionBar.frame.size.height + _sectionBar.frame.origin.y, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - _sectionBar.frame.size.height - _sectionBar.frame.origin.y - 44);
    _scrollView.backgroundColor = [UIColor whiteColor];
    
    CGRect rect = _scrollView.bounds;
    UITableView *tab1 = [[UITableView alloc] init];
    tab1.frame = rect;
    tab1.backgroundColor = [UIColor blueColor];
    [_scrollView addSubview:tab1];
    
    UITableView *tab2 = [[UITableView alloc] init];
    rect.origin.x += rect.size.width;
    tab2.frame = rect;
    tab2.backgroundColor = [UIColor redColor];
    [_scrollView addSubview:tab2];

    UITableView *tab3 = [[UITableView alloc] init];
    rect.origin.x += rect.size.width;
    tab3.frame = rect;
    tab3.backgroundColor = [UIColor purpleColor];
    [_scrollView addSubview:tab3];
    
    UITableView *tab4 = [[UITableView alloc] init];
    rect.origin.x += rect.size.width;
    tab4.frame = rect;
    tab4.backgroundColor = [UIColor grayColor];
    [_scrollView addSubview:tab4];
    NSLog(@"%lf",_scrollView.contentOffset.x);

    _scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width * _titleArray.count, _scrollView.frame.size.height);
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
}


- (void)setUpTableView{

}

#pragma mark - delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    _sectionBar.offset = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    NSLog(@"%lf",scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    _sectionBar.pag = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    NSLog(@"%lf",scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width);
}

- (void)sectionBar:(HFOLsectionBar *)sectionBar selectButtonIndex:(NSInteger)index{
    [UIView animateKeyframesWithDuration:0.25 delay:0 options:UIViewKeyframeAnimationOptionLayoutSubviews animations:^{
        self.scrollView.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width * index, 0);
    } completion:nil];
    

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
